// import { IAppOption } from "../../appoption"
// import { CarService } from "../../service/car"
// import { ProfileService } from "../../service/profile"
// import { rental } from "../../service/proto_gen/rental/rental_pb"
// import { TripService } from "../../service/trip"
// import { routing } from "../../utils/routing"

// const app = getApp<IAppOption>()
interface Marker {
  iconPath: string
  id: number
  latitude: number
  longitude: number
  width: number
  height: number
}
//const defaultAvatar = '/resources/car.png'
const initialLat = 29.761267625855936
const initialLng = 121.87264654736123
Page({
  data: {
    avatarURL: '',
    setting: {
      skew: 0,
      rotate: 0,
      showLocation: false,
      showScale: false,
      subKey: '',
      layerStyle: 1,
      enableZoom: true,
      enableScroll: true,
      enableRotate: false,
      showCompass: false,
      enable3D: false,
      enableOverlooking: false,
      enableSatellite: false,
      enableTraffic: false,
    },
    location: {
      latitude: initialLat,
      longitude: initialLng,
    },
    scale: 16,
    markers: [] as Marker[],
  },
  onMyLocationTap() {
    wx.getLocation({
      type: 'gcj02',
      success: res => {
        this.setData({
          location: {
            latitude: res.latitude,
            longitude: res.longitude,
          },
        })
      }, 
      fail: () => {
        wx.showToast({
          icon: 'none',
          title: '请前往设置页授权',
        })
      }
    })
  },
  onScanTap(){
    wx.scanCode({
      success:()=>{
        const carID = 'cra123'
        const redirectURL = `/pages/lock/lock?car_id=${carID}`
        wx.navigateTo({
          url:`/pages/register/register?redirect=${encodeURIComponent(redirectURL)}`,
        })
      },
      fail:()=>console.error
    })
  },
})
